home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gtlayout.lha / Source / LTP_Rescale.c < prev    next >
C/C++ Source or Header  |  1998-09-09  |  3KB  |  139 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. VOID
  17. LTP_ResetListViewTextAttrs(ObjectNode *group)
  18. {
  19.     ObjectNode *node;
  20.  
  21.     SCANGROUP(group,node)
  22.     {
  23.         if(node->Type == GROUP_KIND)
  24.             LTP_ResetListViewTextAttrs(node);
  25.         else
  26.         {
  27.             if(node->Type == LISTVIEW_KIND && node->Special.List.TextAttr)
  28.                 node->Special.List.TextAttr = NULL;
  29.         }
  30.     }
  31. }
  32.  
  33. VOID
  34. LTP_Rescale(LayoutHandle *handle,BOOL trimWidth,BOOL trimHeight)
  35. {
  36.     STATIC const struct TextAttr topazAttr =
  37.     {
  38.         "topaz.font",
  39.         8,
  40.         FS_NORMAL,
  41.         FPF_ROMFONT | FPF_DESIGNED
  42.     };
  43.  
  44.     if(handle->TextAttr != &topazAttr && (Stricmp(handle->TextAttr->ta_Name,"topaz.font") || handle->TextAttr->ta_YSize != 8))
  45.     {
  46.         struct RastPort *rp;
  47.  
  48.         LONG    oldWidth;
  49.         LONG    oldHeight;
  50.         LONG    count;
  51.         LONG    i;
  52.         LONG    total;
  53.         LONG    width;
  54.         UBYTE    glyph;
  55.         LONG    oldStyle;
  56.  
  57.         rp = &handle->RPort;
  58.  
  59.         oldStyle    = rp->AlgoStyle;
  60.         oldWidth    = handle->GlyphWidth;
  61.         oldHeight    = handle->GlyphHeight;
  62.  
  63.         LTP_ResetListViewTextAttrs(handle->TopGroup);
  64.  
  65.         if(handle->CloseFont)
  66.             CloseFont(rp->Font);
  67.  
  68.         /*
  69.          * Note from Martin:
  70.          * GfxBase->DefaultFont is guaranteed not to ever be removed from
  71.          * memory, so we use that fact...
  72.          *
  73.          * I wasn't comfortable with that assumption, so I returned to
  74.          * the old way of doing it in v26.17
  75.          */
  76.  
  77.         Forbid();
  78.  
  79.         LTP_GetDefaultFont((struct TTextAttr *)(handle->TextAttr = &handle->CopyTextAttr));
  80.  
  81.         LTP_SetFont(handle,LTP_OpenFont(handle->TextAttr));
  82.  
  83.         handle->CloseFont = TRUE;
  84.  
  85.         Permit();
  86.  
  87.         SetSoftStyle(rp,FSF_BOLD | FSF_UNDERLINED,FSF_BOLD | FSF_UNDERLINED);
  88.  
  89.         FOREVER
  90.         {
  91.             count = total = 0;
  92.  
  93.             for(i = 32 ; i < 256 ; i++)
  94.             {
  95.                 if(i == 128)
  96.                     i = 160;
  97.  
  98.                 glyph = i;
  99.  
  100.                 width = TextLength(rp,&glyph,1);
  101.  
  102.                 if(width > 0 && width < 32768)
  103.                 {
  104.                     total += width;
  105.                     count++;
  106.                 }
  107.             }
  108.  
  109.             if((trimWidth && (total / count >= oldWidth)) || (trimHeight && (rp->TxHeight >= oldHeight)))
  110.             {
  111.                 if(handle->TextAttr == &topazAttr || (!Stricmp(handle->TextAttr->ta_Name,"topaz.font") && handle->TextAttr->ta_YSize == 8))
  112.                     break;
  113.                 else
  114.                 {
  115.                     if(handle->CloseFont)
  116.                         CloseFont(rp->Font);
  117.  
  118.                     handle->TextAttr = (struct TextAttr *)&topazAttr;
  119.                     LTP_SetFont(handle,OpenFont(handle->TextAttr));
  120.  
  121.                     handle->CloseFont = TRUE;
  122.                 }
  123.             }
  124.             else
  125.             {
  126.                 handle->Rescaled = TRUE;
  127.  
  128.                 LTP_ResetGroups(handle->TopGroup);
  129.  
  130.                 LTP_GlyphSetup(handle,handle->TextAttr);
  131.  
  132.                 break;
  133.             }
  134.         }
  135.  
  136.         SetSoftStyle(rp,oldStyle,FSF_BOLD | FSF_UNDERLINED);
  137.     }
  138. }
  139.